/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tpgen.grammar;

/**
 *
 * @author shanki
 */
public class Variable extends Terminal {
    
    protected Symbol type;
    
    public Variable(String name, Symbol type) {
        super(name);
        
        this.type = type;
    }

    @Override
    public String toString() {
        return "?" + getName() + "_" + type.toString();
    }

    @Override
    public String toUserString() {
        return toString();
    }
    
    public Symbol getType() {
        return type;
    }

    public boolean sameType(Variable b) {
        return this.type.equals(b.type);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Variable) {
            Variable other = (Variable)obj;
            
            return  this.getName().equals(other.getName()) &&
                    this.sameType(other);
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 31 * hash + (this.name != null ? this.name.hashCode() : 0);        
        hash = 31 * hash + (this.type != null ? this.type.hashCode() : 0);
        return hash;
    }
    
    
    
}
